<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@taglib prefix="s" uri="http://www.springframework.org/tags" %>  
<%@taglib prefix="sf" uri="http://www.springframework.org/tags/form" %>  
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<script>
	$(document).ready(function() {
		//聚焦第一个输入框
		$("#name").focus();
		//为inputForm注册validate函数
		$("#inputForm").validate();
	});
	function calcMenuOrder(){
		$pid = $('#pid');
		$('#menuOrder').val(parseInt($pid.find('option:selected').attr('order'))+1);
		$('#level').val($pid.find('option:selected').val()=='0'?"1":"2");
	}
</script>
<div class="row-fluid">
	<div class="span12">
		<sf:form id="inputForm" commandName="menu" cssClass="form-horizontal" action="../update">
			<sf:hidden path="id" />
			<div class="control-group">
				<label class="control-label" for="name">菜单名称:</label>
				<div class="controls">
					<sf:input path="name" cssClass="input-large required" />
				</div>
			</div>
			<div class="control-group">
				<label class="control-label" for="pid">上级菜单:</label>
				<div class="controls">
				 	<sf:select path="pid" onchange="calcMenuOrder()">
				 			<option value="0" order="${menuCount-1 }">--None--</option>
					 	<c:forEach items="${topLevelMenus }" var="p">
					 		<option value="${p.id }" order="${p.menuOrder}" <c:if test="${menu.pid==p.id}">selected</c:if>>${p.name }</option>
					 	</c:forEach>
				 	</sf:select>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label" for="level">层级:</label>
				<div class="controls">
					<sf:input path="level" cssClass="input-small" readonly="true"/>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label" for="menuOrder">顺序:</label>
				<div class="controls">
					<sf:input path="menuOrder" cssClass="input-small required" />
<!-- 					<a href="javascript:void(0)" onclick="calcMenuOrder()">自动计算</a> -->
				</div>
			</div>			
			<div class="control-group">
				<label class="control-label" for="url">URL:</label>
				<div class="controls">
					<sf:input path="url" cssClass="input-large required" />
				</div>
			</div>
			<div class="control-group">
				<label class="control-label" for="comment">备注:</label>
				<div class="controls">
					<textarea name="comment" class="input-large"></textarea>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label" for="btnSave">&nbsp;</label>
				<div class="controls">
					<input id="btnSave" class="btn btn-primary" type="submit" value="Save"> 
					<input id="btnCancel" class="btn" type="button" value="Cancel" onclick="history.back()">
				</div>
			</div>
		</sf:form>
		
	</div><!-- span12 end -->
	
</div> <!-- row-fluid end -->
